﻿/*
 * StreamHelper
 * 
 * Author: snowdreamist
 * Date: 2011/11/19
 * 
 */


using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BitTorrentSharp.Helpers
{
    public static class StreamHelper
    {
        /// <summary>
        /// If source stream hasn't prepared in memory, then, peek action
        /// may get wrong value
        /// This method prepared the whole stream in memory
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static Stream PreparedStream(this Stream source)
        {
            if (source == null)
                throw new ArgumentNullException("source");

            MemoryStream stream = new MemoryStream();
            source.CopyTo(stream);

            stream.Seek(0, SeekOrigin.Begin);

            return stream;
        }
    }
}
